﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Configuration;
using System.Data;
using System.Web;
//using QIMSServer.Dao;

namespace MaxStudio.Concrete.DBUtility
{
    public class QIMSUtility
    {
        public static string md5(string str)
        {
            MD5 m = new MD5CryptoServiceProvider();
            byte[] s = m.ComputeHash(UnicodeEncoding.UTF8.GetBytes(str));
            return BitConverter.ToString(s);
        }

        public static DateTime getCurrentDateTime()
        {
            try
            {
                if (null == HttpContext.Current || HttpContext.Current.Application[ConcreteConstants.TIME_DIFF] == null)
                    return DateTime.Now;
                else
                {
                    double milliseconds = (double)HttpContext.Current.Application[ConcreteConstants.TIME_DIFF];
                    return DateTime.Now.AddMilliseconds(-milliseconds);
                }
            }
            catch
            {
            }
            return DateTime.Now;
        }

        public static double getTimeDiff(DateTime before, DateTime after)
        {
            TimeSpan ts = after.Subtract(before);
            return ts.TotalMilliseconds;
        }

        //public static bool canAccess(String url, IList functionURLs)
        //{
        //    if (functionURLs == null)
        //        return false;
        //    if (url.IndexOf("?") != -1)
        //    {
        //        url = url.Substring(0, url.IndexOf("?"));
        //    }
        //    for (int i = 0; i < functionURLs.Count; i++)
        //    {
        //        FunctionURL furl = (FunctionURL)functionURLs[i];
        //        if (url.EndsWith(furl.URL) || furl.URL.EndsWith(url))
        //        {
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        //public static bool canAccessFun(String functionID, IList functions)
        //{
        //    if (functions == null)
        //        return false;
        //    for (int i = 0; i < functions.Count; i++)
        //    {
        //        FunctionItem f = (FunctionItem)functions[i];
        //        if (f.id.ToString().Equals(functionID))
        //        {
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        
    }
}
